from manim import *
class CustomCurve(VMobject):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        # 定义自定义曲线的控制点
        points = [
            [-18,10,0],
            [-27,0,0],
            [-18,-20,0]
            
        ]
        self.set_points_smoothly(points)
class CustomCurve1(VMobject):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        # 定义自定义曲线的控制点
        points = [
            [5,15,0],
            [-2,10,0],
            [5,-15,0]
            
        ]
        self.set_points_smoothly(points)

class CustomCurve2(VMobject):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        # 定义自定义曲线的控制点
        points = [
            [30,20,0],
            [28,15,0],
            [30,10,0]
            
        ]
        self.set_points_smoothly(points)

class CustomCurve3(VMobject):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        # 定义自定义曲线的控制点
        points = [
            [121,22,0],
            [117,15,0],
            [121,8,0]
            
        ]
        self.set_points_smoothly(points)

class CustomCurve4(VMobject):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        # 定义自定义曲线的控制点
        points = [
            [145,25,0],
            [140,22,0],
            [145,19,0]
            
        ]
        self.set_points_smoothly(points)
class CustomCurve5(VMobject):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        # 定义自定义曲线的控制点
        points = [
            [160,12,0],
            [155,8,0],
            [160,4,0]
            
        ]
        self.set_points_smoothly(points)
class CustomCurve6(VMobject):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        # 定义自定义曲线的控制点
        points = [
            [25,-5,0],
            [22.5,-12.5,0],
            [20,-15,0],
            [22.5,-17.5,0],
            [25,-25,0],
            
        ]
        self.set_points_smoothly(points)
class CustomCurve7(VMobject):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        # 定义自定义曲线的控制点
        points = [
            [55,-12,0],
            [50,-15,0],
            [55,-18,0]
            
        ]
        self.set_points_smoothly(points)

class CustomCurve8(VMobject):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        # 定义自定义曲线的控制点
        points = [
            [122,-15,0],
            [119,-16,0],
            [116,-23,0],
            [112,-25,0],
            [116,-27,0],
            [119,-34,0],
            [122,-35,0],
            
        ]
        self.set_points_smoothly(points)

class CustomCurve9(VMobject):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        # 定义自定义曲线的控制点
        points = [
            [-18,10,0],
            [-27,0,0],
            [-18,-45,0]
            
        ]
        self.set_points_smoothly(points)
class CustomCurve10(VMobject):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        # 定义自定义曲线的控制点
        points = [
            [5,-40,0],
            [0,-45,0],
            [5,-55,0]
            
        ]
        self.set_points_smoothly(points)



class math1(MovingCameraScene):
    def construct(self):
        self.camera.background_color = BLACK  # 设置背景颜色
        self.camera.frame_width = 100  # 设置边框宽度
        self.camera.frame_height = 60  # 设置边框高度
        self.camera.pixel_height = 1080  # 设置像素高度
        self.camera.pixel_width = 1920  # 设置像素宽度
        self.camera.center = ORIGIN  # 设置中心点位置
        self.camera.scale_factor = 1.0  # 设置缩放因子
        #设置横线
        for i in range(60*2+1):       
            dot1=Dot([-500,5*(i-60),0]).set_opacity(0.5)
            dot2=Dot([500,5*(i-60),0]).set_opacity(0.5)
            if i==6:
                line1=Line(dot1,dot2).set_color(WHITE).set_opacity(0.5)
                
            else:
                line1=Line(dot1,dot2).set_color(WHITE).set_opacity(0.5)
               
            self.add(dot1,dot2,line1)
        #设置竖线
        for i in range(100*2+1):        
            dot3=Dot([(i-100)*5,-300,0]).set_opacity(0.5)
            dot4=Dot([(i-100)*5,300,0]).set_opacity(0.5)
            if i==10:
                line2=Line(dot3,dot4).set_color(WHITE).set_opacity(0.5)
                
            else:
                line2=Line(dot3,dot4).set_color(WHITE).set_opacity(0.5)
            self.add(dot3,dot4,line2)
        #设置三个点
        dot1 = Dot(radius=1, color=RED)  
        dot1.move_to([-47.5,27.5,0]) 
        dot2 = Dot(radius=1, color=YELLOW)  
        dot2.move_to([-42.5,27.5,0])  
        dot3 = Dot(radius=1, color=GREEN)  
        dot3.move_to([-37.5,27.5,0])
        
        #镜头跟进效果 
        self.camera.frame.save_state()
        #题目出现
        #主题展开：
        #1文本
        text = Tex(
                    r"\text{多元函数求极值}",color=PURPLE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-38,0,0])
        #2框框标
        rectangle=Rectangle(color=BLUE,fill_opacity=0.0,width=20,height=5
                            ,stroke_color=BLUE,stroke_width=20)
        rectangle.move_to([-38,0,0])
        self.play(Write(text),Create(rectangle))
         #3箭头
        arrow1 = Arrow(start=[-27,2.5,0],end=[-18,10,0], color=RED
                       , stroke_width=20, tip_length=1)
        arrow2 = Arrow(start=[-27,-2.5,0],end=[-18,-20,0], color=RED
                       , stroke_width=20, tip_length=1)
        #self.play(Create(arrow1),Create(arrow2))
        curve = CustomCurve(color=RED, stroke_width=20)
        
        # 添加到场景并播放动画
        self.play(Create(curve))
        
        text1 = Tex(
                    r"\text{解题思路}"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-10,10,0])
        text2 = Tex(
                    r"\text{题型分类}"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-10,-20,0])
        text3 = Tex(
                    r"\text{(理论框架)}",color=YELLOW
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).next_to(text1,DOWN,buff=1)
        text4 = Tex(
                    r"\text{(实战应用)}",color=YELLOW
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).next_to(text2,DOWN,buff=1)
        

        self.play(Write(text1),Write(text2),Write(text3),Write(text4))
       
        
        #2框框标
        rectangle1=Rectangle(color=BLUE,fill_opacity=0.0,width=12,height=8
                            ,stroke_color=GREEN,stroke_width=20)
        rectangle1.move_to([-10,9,0])
        self.play(Create(rectangle1))

        curve1 = CustomCurve1(color=RED, stroke_width=20)
        
        # 添加到场景并播放动画
        self.play(Create(curve1))

        text5 = Tex(
                    r"\text{无条件极值}",color=GREEN
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([13,15,0])
        text6 = Tex(
                    r"\text{条件极值}",color=GREEN
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([13,-15,0])
        self.play(Write(text5),Write(text6))

        #2框框标
        rectangle2=Rectangle(color=BLUE,fill_opacity=0.0,width=13,height=5
                            ,stroke_color=PURPLE,stroke_width=20)
        rectangle2.move_to([13,15,0])
        self.play(Create(rectangle2))

        text7 = Tex(
                    r"\text{令}"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([25,15,0])
        self.play(Write(text7))

        curve2 = CustomCurve2(color=WHITE, stroke_width=20)
        
        # 添加到场景并播放动画
        self.play(Create(curve2))

        text8 = Tex(
                    r"$f_{x}=0$",color=RED
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([35,20,0])
        text9 = Tex(
                    r"$f_{y}=0$",color=RED
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([35,10,0])
        self.play(Write(text9),Write(text8))
        self.play(self.camera.frame.animate.scale(1.2).move_to([0,0,0]))
        rectangle30=Rectangle(color=BLUE,fill_opacity=0.0,width=30.5,height=12
                            ,stroke_color=BLUE,stroke_width=20)
        rectangle30.move_to([39,15,0])
        
        text190 = Tex(
                    r"\text{解方程可优化}",color=GREEN
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).next_to(rectangle30,UP,buff=3)
        
        #箭头引出
        arrow = Arrow(start=[40,15,0],end=[45,15,0], color=YELLOW
                       , stroke_width=20, tip_length=1)
        self.play(Create(arrow),self.camera.frame.animate.scale(1).move_to([45,15,0]))
        text10 = Tex(
                    r"\text{得驻点}",color=YELLOW
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([50,15,0])
        self.play(Write(text10),self.camera.frame.animate.scale(1).move_to([60,15,0]))

        text11 = Tex(
                    r"$\left( x_{1},y_{1}\right) $",color=GREEN
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([60,23,0])
        text12 = Tex(
                    r"$\left( x_{2},y_{2}\right) $",color=GREEN
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([60,17,0])
        text13 = Tex(
                    r"$\ldots $",color=GREEN
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([60,12,0])
        text14 = Tex(
                    r"$\left( x_{n},y_{n}\right) $",color=GREEN
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([60,7,0])
        self.play(Create(text11),Create(text12),Create(text13),Create(text14))
        self.play(Create(rectangle30))
        self.play(Create(text190))

        #箭头引出
        arrow1 = Arrow(start=[65,15,0],end=[75,15,0], color=BLUE
                       , stroke_width=20, tip_length=1)
        
        text15 = Tex(
                    r"\text{计算}",color=PURPLE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([70,17.5,0])
        self.play(Create(text15),Create(arrow1),self.camera.frame.animate.scale(1).move_to([70,15,0]))

        text16 = Tex(
                    r"$A=f_{xx}\left( x_{i},y_{i}\right) $",color=WHITE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([85,20,0])
        
        text17 = Tex(
                    r"$B=f_{xy}\left( x_{i},y_{i}\right) $",color=WHITE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([85,15,0])
        
        text18 = Tex(
                    r"$C=f_{yy}\left( x_{i},y_{i}\right) $",color=WHITE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([85,10,0])
        self.play(Create(text18),Create(text16),Create(text17),self.camera.frame.animate.scale(1).move_to([85,15,0]))
        rectangle3=Rectangle(color=BLUE,fill_opacity=0.0,width=20,height=16
                            ,stroke_color=RED,stroke_width=20)
        rectangle3.move_to([85,15,0])
        self.play(Create(rectangle3))
        text19 = Tex(
                    r"\text{宏}$\rightarrow $\text{赋值}$\rightarrow $\text{微}",color=YELLOW
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).next_to(rectangle3,UP,buff=3)
        self.play(Create(text19))

         #箭头引出
        arrow2 = Arrow(start=[97,15,0],end=[105,15,0], color=GREEN
                       , stroke_width=20, tip_length=1)
        
        text20 = Tex(
                    r"\text{判断}",color=BLUE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([101,17.5,0])
        self.play(Create(text20),Create(arrow2),self.camera.frame.animate.scale(1).move_to([101,15,0]))
        text21 = Tex(
                    r"$AC-B^{2}$",color=PURPLE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([111,15,0])
        self.play(Create(text21),self.camera.frame.animate.scale(1).move_to([111,15,0]))

        curve3 = CustomCurve3(color=WHITE, stroke_width=20)
        
        # 添加到场景并播放动画
        self.play(Create(curve3))
        
        text22 = Tex(
                    r"$ >0$",color=RED
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([126,22,0])
        text23 = Tex(
                    r"$ =0$",color=RED
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([126,8,0])
        text24 = Tex(
                    r"$ <0$",color=RED
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([126,15,0])
        text25 = Tex(
                    r"\text{(是极值)}",color=YELLOW
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).next_to(text22,RIGHT,buff=1)
        text26 = Tex(
                    r"\text{(失效)",color=YELLOW
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).next_to(text23,RIGHT,buff=1)
        text27 = Tex(
                    r"\text{(不是极值)",color=YELLOW
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).next_to(text24,RIGHT,buff=1)
        self.play(Create(text22),Create(text23),Create(text24),Create(text25),Create(text26),Create(text27),self.camera.frame.animate.scale(1).move_to([130,15,0]))


        curve4 = CustomCurve4(color=GREEN, stroke_width=20)
        
        # 添加到场景并播放动画
        self.play(Create(curve4))
        text28 = Tex(
                    r"$ A>0$",color=BLUE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([150,25,0])
        text29 = Tex(
                    r"$ A<0$",color=BLUE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([150,19,0])
        text30 = Tex(
                    r"\text{(极小值)}",color=PURPLE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).next_to(text28,RIGHT,buff=1)
        text31 = Tex(
                    r"\text{(极大值)",color=PURPLE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).next_to(text29,RIGHT,buff=1)
        self.play(Create(text28),Create(text29),Create(text30),Create(text31),self.camera.frame.animate.scale(1).move_to([140,15,0]))

        #箭头引出
        arrow3 = Arrow(start=[138,8,0],end=[145,8,0], color=GREEN
                       , stroke_width=20, tip_length=1)
        self.play(Create(arrow3),self.camera.frame.animate.scale(1).move_to([150,15,0]))
        text32 = Tex(
                    r"\text{用定义}",color=BLUE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([150,8,0])
        self.play(Create(text32))
        curve5 = CustomCurve5(color=PURPLE, stroke_width=20)
        
        # 添加到场景并播放动画
        self.play(Create(curve5))

        text33 = Tex(
                    r"\text{极限保号性,脱帽法}",color=WHITE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([175,12,0])
        text34 = Tex(
                    r"\text{不等式放缩}",color=WHITE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([170,4,0])
        self.play(Create(text33),Create(text34))

        self.play(self.camera.frame.animate.scale(2).move_to([70,15,0]))
        self.wait(0.3)
        self.play(self.camera.frame.animate.scale(0.5).move_to([0,0,0]))
         #2框框标
        rectangle4=Rectangle(color=BLUE,fill_opacity=0.0,width=13,height=5
                            ,stroke_color=PURPLE,stroke_width=20)
        rectangle4.move_to([13,-15,0])
        self.play(Create(rectangle4))

        curve6 = CustomCurve6(color=WHITE, stroke_width=20)
        
        # 添加到场景并播放动画
        self.play(Create(curve6))

        text35 = Tex(
                    r"\text{1.整体带入}$\rightarrow $\text{简化目标函数}",color=BLUE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([43,-5,0])
        text36 = Tex(
                    r"\text{(二元化一元,轻松得到结果)}",color=RED
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).next_to(text35,RIGHT,buff=1)
        self.play(Create(text35),self.camera.frame.animate.scale(1).move_to([40,-5,0]))
        self.play(Create(text36))
        text37 = Tex(
                    r"\text{2.均值,柯西不等式}",color=BLUE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([38,-15,0])
        self.play(Create(text37),self.camera.frame.animate.scale(1).move_to([50,-5,0]))
        curve7 = CustomCurve7(color=GREEN, stroke_width=20)
        
        # 添加到场景并播放动画
        self.play(Create(curve7))
        text38 = Tex(
                    r"\text{均值}",color=YELLOW
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([60,-12,0])
        text380 = Tex(
                    r"\text{(特征:平方和且系数相等)}",color=GREEN
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).next_to(text38,RIGHT,buff=1)
        text39 = Tex(
                    r"\text{柯西}",color=YELLOW
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([60,-18,0])
        text390 = Tex(
                    r"\text{(特征:平方和且系数不等)}",color=GREEN
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).next_to(text39,RIGHT,buff=1)
        self.play(Create(text38),Create(text39),self.camera.frame.animate.scale(1).move_to([60,-15,0]))
        self.play(Create(text380))
        self.play(Create(text390))
        text40 = Tex(
                    r"\text{3.拉格朗日乘数法}",color=BLUE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([38,-25,0])
        self.play(Create(text40),self.camera.frame.animate.scale(1).move_to([50,-25,0]))
        text41 = Tex(
                    r"\text{设}$L\left( x,y,z,\lambda \right) =f\left( x,y\right) +\lambda \varphi \left( x,y,z\right) $",color=WHITE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([75,-25,0])
        self.play(Create(text41),self.camera.frame.animate.scale(1).move_to([65,-25,0]))
        rectangle5=Rectangle(color=BLUE,fill_opacity=0.0,width=8,height=5
                            ,stroke_color=YELLOW,stroke_width=20)
        rectangle5.move_to([77.5, -25, 0])
        self.play(Create(rectangle5))
        text400 = Tex(
                    r"\text{目标函数}",color=BLUE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).next_to(rectangle5,DOWN,buff=1)
        self.play(Create(text400))
        text4000 = Tex(
                    r"\text{(先考虑优化)}",color=GREEN
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).next_to(text400,DOWN,buff=1)
        self.play(Create(text4000))

        text40000 = Tex(
                    r"\text{求}$d=\sqrt{x^{2}+y^{2}}\min $",color=WHITE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).next_to(text4000,DOWN,buff=5)
        self.play(Create(text40000))
        self.wait(0.3)
        text400000 = Tex(
                    r"\text{求}$\left( x^{2}+y^{2}\right) _{\min }$",color=BLUE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).next_to(text4000,DOWN,buff=5)
        self.play(
            ReplacementTransform(text40000,text400000)
        )
        self.wait(0.3)
        self.play(FadeOut(text400000))
        rectangle6=Rectangle(color=BLUE,fill_opacity=0.0,width=11,height=5
                            ,stroke_color=BLUE,stroke_width=20)
        rectangle6.move_to([91, -25, 0])
        self.play(Create(rectangle6))
        text401 = Tex(
                    r"\text{约束方程}",color=GREEN
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).next_to(rectangle6,DOWN,buff=1)
        self.play(Create(text401))

        #箭头引出
        arrow4 = Arrow(start=[97,-25,0],end=[107,-25,0], color=RED
                       , stroke_width=20, tip_length=1)
        self.play(Create(arrow4),self.camera.frame.animate.scale(1).move_to([85,-25,0]))
        text42 = Tex(
                    r"\text{令}",color=PURPLE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([109,-25,0])
        self.play(Create(text42),self.camera.frame.animate.scale(1).move_to([100,-25,0]))
        curve8 = CustomCurve8(color=GREEN, stroke_width=20)
        
        # 添加到场景并播放动画
        self.play(Create(curve8))
        text43 = Tex(
                    r"$L_{x}=0$",color=YELLOW
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([127,-15,0])
        text44 = Tex(
                    r"$L_{y}=0$",color=YELLOW
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([127,-21,0])
        text45 = Tex(
                    r"$L_{z}=0$",color=YELLOW
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([127,-27,0])
        text46 = Tex(
                    r"$L_{\lambda }=0$",color=YELLOW
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([127,-35,0])
        self.play(Create(text43),Create(text44),Create(text45),Create(text46),self.camera.frame.animate.scale(1).move_to([115,-25,0]))
        rectangle7=Rectangle(color=BLUE,fill_opacity=0.0,width=10,height=16
                            ,stroke_color=BLUE,stroke_width=20)
        rectangle7.move_to([127,-21,0])
        self.play(Create(rectangle7))
        text47 = Tex(
                    r"\text{含参方程}",color=GREEN
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).next_to(rectangle7,UP,buff=1)
        self.play(Create(text47))
        rectangle8=Rectangle(color=BLUE,fill_opacity=0.0,width=10,height=5
                            ,stroke_color=PURPLE,stroke_width=20)
        rectangle8.move_to([127,-35,0])
        self.play(Create(rectangle8))
        text48 = Tex(
                    r"\text{无参方程}",color=RED
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).next_to(rectangle8,DOWN,buff=1)
        self.play(Create(text48))
        #箭头引出
        arrow5 = Arrow(start=[137,-25,0],end=[147,-25,0], color=GREEN
                       , stroke_width=20, tip_length=1)
        self.play(Create(arrow5),self.camera.frame.animate.scale(1).move_to([130,-25,0]))
        text49 = Tex(
                    r"\text{解方程组}",color=BLUE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([142,-22,0])
        text50 = Tex(
                    r"$\star\star\star$",color=PURE_RED
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([142,-28,0])
        self.play(Create(text49),self.camera.frame.animate.scale(1).move_to([140,-25,0]))
        text51 = Tex(
                    r"\text{得驻点}",color=WHITE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([152,-25,0])
        self.play(Create(text51),self.camera.frame.animate.scale(1).move_to([150,-25,0]))

        text52 = Tex(
                    r"$\left( x_{1},y_{1}\right) $",color=GREEN
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([162,-18,0])
        text53 = Tex(
                    r"$\left( x_{2},y_{2}\right) $",color=GREEN
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([162,-23,0])
        text54 = Tex(
                    r"$\ldots $",color=GREEN
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([162,-28,0])
        text55 = Tex(
                    r"$\left( x_{n},y_{n}\right) $",color=GREEN
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([162,-32,0])
        self.play(Create(text52),Create(text53),Create(text54),Create(text55),self.camera.frame.animate.scale(1).move_to([160,-25,0]))
        #箭头引出
        arrow6 = Arrow(start=[167,-25,0],end=[177,-25,0], color=BLUE
                       , stroke_width=20, tip_length=1)
        self.play(Create(arrow6),self.camera.frame.animate.scale(1).move_to([172,-25,0]))
        text56 = Tex(
                    r"\text{比较}",color=WHITE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([180,-25,0])
        self.play(Create(text56))
        text58 = Tex(
                    r"$f\left( x_{1},y_{1}\right) $",color=RED
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([191,-18,0])
        text59 = Tex(
                    r"$f\left( x_{2},y_{2}\right) $",color=RED
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([191,-23,0])
        text60 = Tex(
                    r"$\ldots $",color=RED
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([191,-28,0])
        text61 = Tex(
                    r"$f\left( x_{n},y_{n}\right) $",color=RED
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([191,-32,0])
        self.play(Create(text58),Create(text59),Create(text60),Create(text61))
        text57 = Tex(
                    r"\text{大小关系}",color=WHITE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([202,-25,0])
        self.play(Create(text57))
        
        self.play(self.camera.frame.animate.scale(1).move_to([142,-28,0]))
        self.play(Create(text50))
        self.play(self.camera.frame.animate.scale(0.5).move_to([142,-28,0]))
        self.wait()
        self.play(self.camera.frame.animate.scale(2).move_to([142,-28,0]))
        self.wait()
        self.play(self.camera.frame.animate.scale(2.2).move_to([80,-15,0]))
        self.wait()
        curve9 = CustomCurve9(color=RED, stroke_width=20)
        text211 = Tex(
                    r"\text{题型分类}"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-10,-45,0])
        
        text411 = Tex(
                    r"\text{(实战应用)}",color=YELLOW
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).next_to(text211,DOWN,buff=1)
        combined1 = Group(text4, text2)
        combined2 = Group(text411, text211)
        

        self.play(
            ReplacementTransform(curve,curve9),
            ReplacementTransform(combined1,combined2)

        )
        self.play(self.camera.frame.animate.scale(0.5).move_to([-10,-45,0]))
        self.wait()
        curve10 = CustomCurve10(color=RED, stroke_width=20)
        self.play(Create(curve10),self.camera.frame.animate.scale(1).move_to([10,-45,0]))
        text58 = Tex(
                    r"\text{无条件极值}",color=GREEN
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([12,-40,0])
        text59 = Tex(
                    r"\text{条件极值}",color=GREEN
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([12,-55,0])
        #2框框标
        rectangle100=Rectangle(color=BLUE,fill_opacity=0.0,width=13,height=8
                            ,stroke_color=BLUE,stroke_width=20)
        rectangle200=Rectangle(color=BLUE,fill_opacity=0.0,width=13,height=8
                            ,stroke_color=BLUE,stroke_width=20)
        rectangle100.move_to([12,-40,0])
        rectangle200.move_to([12,-55,0])
        self.play(Create(text58),Create(text59),Create(rectangle100),Create(rectangle200))

        
        text600 = Tex(
                    r"\text{等式型}",color=WHITE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([27.5,-45,0])
        text601 = Tex(
                    r"\text{约束}",color=PURPLE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).next_to(text600,RIGHT,buff=1)
        
        self.play(Create(text600),Create(text601),self.camera.frame.animate.scale(1).move_to([50,-45,0]))
        text61 = Tex(
                    r"\text{设问1:}",color=RED
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([45,-45,0])
        text62 = Tex(
                    r"\text{求}$f\left( x,y\right) $\text{的极值}",color=YELLOW
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).next_to(text61,RIGHT,buff=1)
        self.play(Create(text61),Create(text62))
        combined3 = Group(text61, text62)
        self.play(combined3.animate().shift(UP*10)) 

        text63 = Tex(
                    r"\text{设问2:}",color=RED
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([45,-45,0])
        text64 = Tex(
                    r"\text{求}$f\left( x,y\right) $\text{在}$x^{2}+y^{2} <1$\text{的极值}",color=YELLOW
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).next_to(text63,RIGHT,buff=1)
        self.play(Create(text63),Create(text64))
        combined4 = Group(text64, text63)
        self.play(combined4.animate().shift(UP*5)) 


        text65 = Tex(
                    r"\text{设问3:}",color=RED
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([45,-45,0])
        text66 = Tex(
                    r"\text{求}$f\left( x,y\right) $\text{在}$x^{2}+y^{2} =1$\text{的极值}",color=YELLOW
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).next_to(text65,RIGHT,buff=1)
        self.play(Create(text65),Create(text66))
        combined5 = Group(text66, text65)
        self.play(combined5.animate().shift(DOWN*10)) 


        text67 = Tex(
                    r"\text{设问4:}",color=GREEN
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([45,-45,0])
        text68 = Tex(
                    r"\text{求}$f\left( x,y\right) $\text{在}$x^{2}+y^{2}\leq 1$\text{的极值}",color=BLUE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).next_to(text67,RIGHT,buff=1)
        text69 = Tex(
                    r"\text{设问4:}",color=GREEN
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([45,-45,0])
        text70 = Tex(
                    r"\text{求}$f\left( x,y\right) $\text{在}$x^{2}+y^{2}\leq 1$\text{的极值}",color=BLUE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).next_to(text69,RIGHT,buff=1)
        text71 = Tex(
                    r"\text{设问4:}",color=GREEN
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([45,-45,0])
        text72 = Tex(
                    r"\text{求}$f\left( x,y\right) $\text{在}$x^{2}+y^{2}\leq 1$\text{的极值}",color=BLUE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).next_to(text71,RIGHT,buff=1)
        self.play(Create(text67),Create(text68),Create(text69),Create(text70),Create(text71),Create(text72))
        combined6 = Group(text67, text68)
        combined7 = Group(text69, text70)
        combined8 = Group(text63, text64)
        combined9 = Group(text65, text66)
        self.play(
            ReplacementTransform(combined6,combined8),
            ReplacementTransform(combined7,combined9)

        )

        self.play(self.camera.frame.animate.scale(2.2).move_to([80,-15,0]))
         #镜头跟进效果 
        self.camera.frame.save_state()
        self.play(self.camera.frame.animate.scale(0.3).move_to([-38,0,0]),run_time=2)

        
        self.play(self.camera.frame.animate.scale(1.5).move_to([40,-10,0]),run_time=2)
        
        self.play(self.camera.frame.animate.scale(1.5).move_to([120,-10,0]),run_time=2)
        self.play(Restore(self.camera.frame))
        self.wait(3)
        

        
